package com.mianyang.zhangsan.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mianyang.zhangsan.common.base.BaseController;
import com.mianyang.zhangsan.common.base.R;
import com.mianyang.zhangsan.model.entity.SecTemplate;
import com.mianyang.zhangsan.service.SecTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author jiangjr
 * @date 2022-12-01
 */
@RestController
@RequestMapping("/template")
public class SecTemplateController extends BaseController {
    @Autowired
    private SecTemplateService templateService;

    /**
     * 新增模板
     */
    @PostMapping("/save")
    public R generatorTemplate(@RequestBody SecTemplate template) {
        templateService.insertTemplate(template);
        return success();
    }

    /**
     * 修改模板
     */
    @PutMapping("/edit")
    public R editTemplate(@RequestBody SecTemplate template) {
        templateService.updateById(template);
        return success();
    }

    /**
     * 查询模板
     */
    @GetMapping("/query")
    public R queryTemplate(SecTemplate template,
                           @RequestParam(value = "current", defaultValue = "1") Integer current,
                           @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<SecTemplate> templatePage = templateService.selectTemplateByPage(template, current, pageSize);
        return success("pages", templatePage);
    }

    /**
     * 删除模板
     */
    @DeleteMapping("/delete/{templateId}")
    public R deleteTemplate(@PathVariable("templateId") Long templateId) {
        templateService.removeById(templateId);
        return success();
    }
}
